<template>
  <svg
    class="svg-icon"
    :style="{
      width: size,
      height: size,
      color,
    }"
  >
    <use :xlink:href="iconName" :fill="color" />
  </svg>
</template>

<script>
export default {
  name: "SvgIcon",
  props: {
    icon: {
      //svg图标名称
      type: String,
      required: true,
    },
    color: {
      type: String,
      default: "",
    },
    size: {
      //svg尺寸
      type: [Number, String],
      default: "2em",
    },
  },
  data() {
    return {};
  },
  computed: {
    iconName() {
      return `#icon-${this.icon}`;
    },
  },
};
</script>

<style scoped>
.svg-icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}
</style>
